package aimis.service;


import aimis.domain.ErrorMsg;
import aimis.domain.History;
import aimis.repo.ErrorMsgMapper;
import aimis.repo.HistoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class InformationServiceImpl implements InformationService {
    @Autowired
    HistoryMapper historyMapper;
    @Override
    public List<History> GetAllHisToryMsg() {
        List<History> histories = historyMapper.getAll();
        return histories;
    }

    @Autowired
    ErrorMsgMapper errorMsgMapper;
    @Override
    public List<ErrorMsg> GetAllErrorMsg() {
        List<ErrorMsg> errorMsgs = errorMsgMapper.getAll();
        return errorMsgs;
    }

    @Override
    public List<History> getAllSearch(String keyWord) {
        List<History> histories = historyMapper.getAll();
        List<History> x1 = new ArrayList<>();
        for (History x : histories) {
            String resultString = x.getId() + "," +
                    x.getDate() + "," +
                    x.getName() + "," +
                    x.getElement1() + "," +
                    x.getElement2() + "," +
                    x.getElement3() + "," +
                    x.getElement4();
            if(resultString.contains(keyWord)){
                x1.add(x);
            }
        }
        return x1;
    }

    @Override
    public void deleteById(String id) {
        historyMapper.deleteById(id);
    }
}
